
/***  DOCUMENTATION LAYER

	Bafflegate Tracker Script

	Last Update: Aug 2007
	Author: Tom at klenwell@gmail.com

SUMMARY	
	Collects user info, assembles a query string, and calls bafflegate log server 
  php file to log data in bafflegate database
  
  <script type="text/javascript" src="tracker.js"></script>
  <script type="text/javascript">
    var baffle_key = 1000;
    bafflelog();    
  </script>
  <noscript><img alt="" src="http://www.domain.com/bafflegate/log.php?bid=$idnum&jsa=0"></noscript>

NOTES
  To link: <script type="text/javascript" src="path/to/file.js"></script>


______________________________________________________________________________*/

// Data we want to collect

  var ref_url = '';
  var page_title = '';
  var agent_name = '';
  var agent_ver = 0.0;
  var agent_str = '';
  var user_os = '';  
  var screen_size = '';
  var screen_depth = 0;
  var is_framed = 0;

// Are we being framed?
if ( window.top != window.self ) is_framed = 1;
 
  
// Get referrer
if ( !is_framed )
{
  ref_url = document.referrer;
}
else
{
  ref_url = window.top.document.referrer;
  frame_url = window.top.location;
}

// Get title
page_title = document.title;

   
// Get agent info
if ( typeof(navigator.appName) != 'undefined' ) agent_name = navigator.appName;
if ( typeof(navigator.appVersion) != 'undefined' ) agent_ver = navigator.appVersion;
if ( typeof(navigator.userAgent) != 'undefined' ) agent_str = navigator.userAgent;
if ( typeof(navigator.platform) != 'undefined' ) user_os = navigator.platform;
if ( typeof(navigator.oscpu) != 'undefined' ) os_cpu = navigator.oscpu;


// Screen info
screen_size = screen.width + "x" + screen.height;
 
if ( typeof(screen.colorDepth) != 'undefined' ) 
{
  screen_depth = screen.colorDepth;
}
else if ( typeof(screen.pixelDepth) != 'undefined' ) 
{
  screen_depth = screen.colorDepth;
}



// bafflegate logger function / assembles query and calls file
function bafflelog()
{
  var qstring = '';
  var qa = '&';
  var q1 = 'key=' + baffle_id + qa;
  var q2 = 'ref=' + escape(ref_url) + qa;
  var q3 = 'ttl=' + escape(page_title) + qa;
  var q4 = 'uos=' + escape(user_os) + qa;
  var q5 = 'ssz=' + screen_size + qa;
  var q6 = 'sdp=' + screen_depth + qa;
  var q7 = 'frm=' + is_framed + qa;
  var q8 = 'jsa=1';
  
  qstring = '?' + q1  + q2 + q3 + q4 + q5 + q6 + q7 + q8;
  
  // debug
  alert(qstring)
  
  // call php logger on server
  var src = '%pphlogger_location%pphlogger.php' + qstring;
  document.open();
	document.write('<script language="JavaScript" type="text/javascript" src="' + src + '"></script>');
	document.close();  
}

